import request from '@/utils/request'

// 1.根据过滤条件查询文章列表
/**
 *
 * @param {*} params 过滤条件
 */
export const getArticles = (params) => {
  return request({
    method: 'GET',
    url: '/mp/v1_0/articles',
    params
  })
}

/**
 * 获取文章频道
 */
export const getArticleChannels = () => {
  return request({
    method: 'GET',
    url: '/mp/v1_0/channels'
  })
}

// 4.新建文章
export const createArticle = function (params, data) {
  return request({
    url: '/mp/v1_0/articles',
    method: 'POST',
    // 用来接收query参数
    params,
    // 用来接收body参数
    data
  })
}

/**
 * 删除文章
 * @param {*} articleId
 */
export const delArticle = function (articleId) {
  return request({
    url: `/mp/v1_0/articles/${articleId}`,
    method: 'DELETE'
  })
}

// 5获取文章详情
export const getArticleDetail = function (id) {
  return request({
    url: `/mp/v1_0/articles/${id}`,
    method: 'GET'
  })
}

// 6.修改文章详情
export const updateArticle = function (id, params, data) {
  return request({
    url: `/mp/v1_0/articles/${id}`,
    method: 'PUT',
    params,
    data
  })
}
